/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cataletra.db;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author arthur
 */
public class Conexao {
    
    private Connection conn;
    private static Conexao singleton;
 
    private Conexao(){
        try {
            String path = "./db/";
            File dir = new File(path);
            if(!dir.exists()){
                dir.mkdir();
            }
            for(int i = 0; i < dir.listFiles().length; i++){
                System.out.println(dir.listFiles()[i]);                
            }
            conn = DriverManager.getConnection("jdbc:hsqldb:file:" + path, "cataletra", "catandoletra");
        } catch(SQLException ex){
            Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 
    public static Conexao getInstance() throws Exception {
        if (singleton == null)
            singleton = new Conexao();
        return singleton;
    }
 
    public Connection getConexao(){
        return conn;
    }
}